/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cabarrus.xltosql.util;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

/**
 *
 * @author moscac
 */
public class JarFileLoader extends URLClassLoader {

    public JarFileLoader(URL[] urls) {
        super(urls);
    }

    public void addFile(String path) throws MalformedURLException {
        //String urlPath = "file:///E://dvrWork//dynamicJarLoad//TestApplet3.jar";
        //String urlPath = "http://www.inkriti.com/temp/TestApplet3.jar";
        addURL(new URL(path));
    }

    public static void main(String args[]) {
        try {
            System.out.println("First attempt...");
            Class.forName("TestApplet");
        } catch (Exception ex) {
            System.out.println("Failed.");

        }

        try {
            URL urls[] = {};

            JarFileLoader cl = new JarFileLoader(urls);
            cl.addFile("file:///E://dvrWork//dynamicJarLoad//TestApplet3.jar");
            cl.addFile("http://www.inkriti.com/temp/TestApplet3.jar");
            System.out.println("Second attempt...");
            cl.loadClass("TestApplet");
            System.out.println("Success!");
        } catch (Exception ex) {
            System.out.println("Failed.");
            ex.printStackTrace();
        }
    }
}
